/**
 * 每个物品有4个维度，设定前三个维度的上限，问第四个维度和最大是多少
 * 一共只有10个物品，显然是枚举每一种可能性，求最大值即可。
 */
#include <bits/stdc++.h>
using namespace std;
 
char *__abc147, *__xyz258, __ma369[100000];
#define __hv007() ((__abc147==__xyz258) && (__xyz258=(__abc147=__ma369)+fread(__ma369,1,100000,stdin),__abc147==__xyz258) ? EOF : *__abc147++)
 
int getInt(){
	int sgn = 1;
	char ch = __hv007();
	while( ch != '-' && ( ch < '0' || ch > '9' ) ) ch = __hv007();
	if ( '-' == ch ) {sgn = 0;ch=__hv007();}
 
	int ret = (int)(ch-'0');
	while( '0' <= (ch=__hv007()) && ch <= '9' ) ret = ret * 10 + (int)(ch-'0');
	return sgn ? ret : -ret;
}
 
#ifndef ONLINE_JUDGE
int const SIZE = 133;
#else
int const SIZE = 1E6+10;
#endif

using _t = array<int, 4>;
int N, A, B, C;
vector<_t> V;

int f(int st){
    int a = 0, b = 0, c = 0;
    int ans = 0;
    for(int i=0;i<N;++i){
        if(st & (1 << i)){
            if((a += V[i][0]) > A) return 0;
            if((b += V[i][1]) > B) return 0;
            if((c += V[i][2]) > C) return 0;
            ans += V[i][3];
        }
    }
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    N = getInt();
    A = getInt();
    B = getInt();
    C = getInt();
    V.assign(N, {});
    for(auto & i : V) i[0]=getInt(),i[1]=getInt(),i[2]=getInt(),i[3]=getInt();
    int st = 0;
    int ans = 0;
    for(int i=1,n=1<<N;i<n;++i){
        ans = max(ans, f(i));
    } 
    cout << ans << endl;
    return 0;
}